package com.sise.aio和bio和nio.nio.基于nio的一个通信案例;

import com.sise.netty.断线重连.Client;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

public class NioServer2 {

    public static void main(String[] args) throws IOException {
        //这是一个链接tcp网络的套接字通道
        ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
        ServerSocket serverSocket = serverSocketChannel.socket();
        serverSocket.bind(new InetSocketAddress(9000));
        serverSocketChannel.configureBlocking(true);
        ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
        System.out.println("wait accept =======");
        SocketChannel socketChannel = serverSocketChannel.accept();
        System.out.println("accept ========");
        while (true) {
            int len = socketChannel.read(byteBuffer);
            if(len>0){
                System.out.println(new String(byteBuffer.array()));
            }
            byteBuffer.clear();
        }
    }
}
